<template>
  <div class="common-search-form-component">
    <a-form :model="queryParams">
      <a-row :gutter="16">
        <a-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6">
          <a-form-item :label="t('file.keyword')">
            <a-input
              v-model:value="queryParams.keyword"
              :placeholder="t('file.searchKeywordPlaceholder')"
              allow-clear
              @keyup.enter="handleSearch"
            />
          </a-form-item>
        </a-col>
        
        <a-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6">
          <a-form-item :label="t('file.type')">
            <a-select
              v-model:value="queryParams.fileType"
              :placeholder="t('file.selectTypePlaceholder')"
              allow-clear
              style="width: 100%"
            >
              <a-select-option 
                v-for="option in fileTypeOptions" 
                :key="option.value" 
                :value="option.value"
              >
                {{ option.label }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        
        <a-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6">
          <a-form-item :label="t('common.dateRange')">
            <a-range-picker
              :value="dateRange || undefined"
              @update:value="$emit('update:dateRange', $event)"
              :placeholder="[t('file.startDate'), t('file.endDate')]"
              style="width: 100%"
            />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </div>
</template>

<script lang="ts" setup>
import type { Dayjs } from 'dayjs'
import type { FileQuery } from '@/types/api/file'
import { useFileTypeOptions } from '../config/searchConfig'

defineOptions({
  name: 'SearchForm'
})

// Props定义
withDefaults(defineProps<{
  queryParams: FileQuery
  dateRange?: [Dayjs, Dayjs] | null
}>(), {
  dateRange: null
})

// Emits定义
const emit = defineEmits(['search', 'reset', 'update:dateRange'])

// 国际化
const { t } = useI18n()

// 配置
const fileTypeOptions = useFileTypeOptions()

// 搜索处理
const handleSearch = () => {
  emit('search')
}
</script>

<style lang="scss" scoped>
@import '@/assets/styles/views/common.scss';
</style> 